package facilius.controller.action.disciplina;

import facilius.model.ServiceLocator;
import facilius.model.pojo.Disciplina;
import org.mentawai.core.BaseAction;

/**
 *
 * @author Graciano
 */
public class DisciplinaUpdateAction extends BaseAction {

    @Override
    public String execute() throws Exception {
        String consequence = ERROR;
        try {
            Disciplina disciplina = new Disciplina();
            disciplina.setId(input.getLong("id"));
            disciplina.setDescricao(input.getString("descricao"));
            disciplina.setNome(input.getString("nome"));

            Long cursoId = input.getLong("cursoId");
            disciplina.setCurso(ServiceLocator.getCursoService().readById(cursoId));

            ServiceLocator.getDisciplinaService().update(disciplina);

            consequence = SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return consequence;
    }
}
